Mouse InputΒΆ
Move the mouse across the screen to change the position of the circles. The positions of the mouse are recorded into an array and played back every frame. Between each frame, the newest value are added to the end of each array and the oldest value is deleted.
from p5 import *
num = 60
mx = [0]*num
my = [0]*num
def setup():
size(640, 360)
no_stroke()
fill(255, 153)
def draw():
background(51)
global num, mx, my
which = frame_count % num
mx[which] = mouse_x
my[which] = mouse_y
for i in range(num):
index = (which+1 + i) % num
ellipse([mx[index], my[index]], i, i)
if __name__ == '__main__':
run()